What is Visual Basic Script in WinCC? Simple VBScript Example

Published on Dec20, 2024 | Category: vbscript
Share this article:

VBScript or visual basic script is a scripting language used for developing and designed of automation and scripting tasks. vb script is commonly used for scripting within HMI environments to automate repetitive tasks, such as tag values, visualization task, alarm handling, network error handling, administrative tasks etc. vbscript is more user friendly scripting language so it is mostly used in industial control system. It is based on Microsoft\'s Visual Basic programming language and is primarily used for automating tasks. in wincc vbscript help to designing more user friendly graphical user interface. wincc hmi also support vbscript. this article only for wincc hmi scripting. you can use this script language in wincc software or wincc tia portal.

add component and tag for script

open or create your project in wincc flexible or wincc tia portal. select HMI and add component to your hmi in this article a button and two input output field and a text field is inserted. after insering these component add input1, input2 tag and select UINT data type in tag table. Assign input1 and input2 tag for input output fields.

img/wincc vbscript/add component and tag for script.webp

how to add vbscript in wincc

to add vbscript in wincc, go to project tree open script and than click to add new vbscript now next step is write a script for hmi. in wincc have two type of script function you can add

in vb script open property to select above script type. by default Sub function. first example is Subroutine function in vbscript and second example is a function vbscript without parameter.

img/wincc vbscript/how to add vbscript in wincc.webp

how to write a vbscript in wincc

after adding script open script in wincc flexible and write a following code in this script example we simply add two input output field value. following are the script subroutine vb script example explanation

img/wincc vbscript/how to write a vbscript in wincc.webp

after creating script click to check script error, if any error occurred during error checking remove the error for next step.

declare vbscript in hmi component in wincc

after creating no error script select button and open button property and select event in event select button press event and select script

img/wincc vbscript/declare script in hmi component in wincc.webp

check script during simulation

in simulation you can check how your actual work in hmi. after assigning script in button event simulate program to test. when wincc simulation start and value of input output fild is changed. supposed in input field value 124 and input filed value is 124 and than add button is pressed result of these input output filed shown in text field.

img/wincc vbscript/check script during simulation.webp

simple example of vbscript function in wincc

in this simple vb script value of increment when increment button is pressed. each click of increment button increase value by 1. so first add button and rename button to increment and a numerical input output field where we show incremental value when button is pressed. Add a script and than add add following script in script editor.

img/wincc vbscript/simple example of vbscript function in wincc.webp

above is the function vbscript in wincc without parameter. This VBScript code defines a function named VBFunction_4 that increments the value of a SmartTag named "tag1" by 1 and then returns the updated value. following is the line by line explanation of vbscript in wincc

declare vbscript function in wincc

after create above script define this vbscript function to button so you can use this script when button clicked. so first goto button property open button event tab and select script.and in input output field declare tag1 in process tag property tab.